/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model.game.disaster.plugin;

import java.awt.Image;
import java.util.Random;
import model.game.GameInterface;
import model.game.disaster.Disaster;
import model.map.cell.Cell;
import model.map.cell.PlantableCell;
import model.utility.ImageUtility;

/**
 * Theft, lost maximum 100 money at the end of day. 10% chance
 */
public class Rain extends Disaster {

  /**
   * Keeps track whether this disaster is active
   */
  private boolean active_;

  /**
   * Random number generator
   */
  private Random random_;

  /**
   * Constructor
   */
  public Rain(GameInterface game) {
    super(game);
    active_ = false;
    random_ = new Random();
  }

  @Override
  public String getName() {
    return "Rain";
  }

  @Override
  public String getDescription() {
    return "Rain pours and water all your cells.";
  }

  @Override
  public void advanceDay() {
    active_ = false;

    // 30% chance of happening every day
    if (random_.nextDouble() > 0.70) {

      // accident happens
      game_.addImportantMessage("Rain pours for the day.");
      active_ = true;

      for (int x = 0; x < game_.getMaps().getField().getColumn(); ++x) {
        for (int y = 0; y < game_.getMaps().getField().getRow(); ++y) {
          Cell cell = game_.getMaps().getField().getCellAt(x,y);
          if (cell.isPlantable()) {
            ((PlantableCell)cell).water();
          }
        }
      }
    }
    
  }

  @Override
  public void advanceTime() {
  }

  @Override
  public boolean isActive() {
    return active_;
  }

  public Image getImage() {
    return ImageUtility.loadImage("resources/pictures/disaster/rain.png");
  }

}
